/**
 * @desc
 *  webpack针对客户端打包的基本配置信息
 *   1.建站系统 开发环境JS webpack打包
 *   2.建站系统 生产环境JS webpack打包
 *   3.建站系统 客户打包
 * @使用场景
 *
 * @author  杨晓东[of1081]
 * @company qianmi.com
 * @Date    15/10/10
 **/

'use strict'
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");


function configFactory() {
	if(!(this instanceof configFactory))
		return  new configFactory();
}
module.exports=configFactory;

/**
 * 生成 一个配置文件
 */
configFactory.prototype.buildConfig=(config,autoOption)=>{
	var entry =config.entry||{},output=config.output||{};

	return Object.assign({},{
		target: 'web',
		entry,
		output,
		resolve: {
			modulesDirectoires: ['', 'web_modules', 'node_modules']
		},
		module: {
			preLoaders:[].concat((config.module && config.module.preLoaders) ?config.module.preLoaders:[]),
			loaders: [
				{ test: /\.less$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader!less-loader') },
				{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" },
				{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" },
				{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" },
				{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" },
				{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml" },
				{ test: /\.js$/,  loader: 'babel',query: {presets: ['es2015', 'stage-0','react','es3']}}, //exclude: /node_modules/,不能加. 不然dll 打包时@qianmi就不会执行了
			],
			postLoaders:[]
		},
		externals: config.externals || {
			// 使用Dll来处理..
			xKit: 'xDllContext.xKit',
			iflux: 'xDllContext.iflux',
			react: 'xDllContext.React',
			immutable: 'xDllContext.Immutable',
			"x-site-integrate":"widow.xSiteIntegrate",
			"react-dom": 'xDllContext.ReactDom',
			"react-addons-pure-render-mixin": 'xDllContext.ReactAddons.PureRenderMixin',
		},
		plugins: [
			// new webpack.DllReferencePlugin({
			// 	context: __dirname,
			// 	manifest: require('../javascripts/dll/vendor-manifest.json')
			// }),
		].concat(config.plugins||[])
	},{devtool:config.devtool});
}